package com.crm.service.impl;

import java.util.Random;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.crm.model.BizBrand;
import com.crm.service.BizBrandService;
import com.crm.util.UUIDUtil;

@Service
public class BizBrandServiceImpl extends BaseServiceImpl<BizBrand> implements BizBrandService{
	
	@Override
	@Transactional
	public int insert(BizBrand record){
		String uuid = UUIDUtil.getUUID();
		record.setBrandId(uuid);
		String code = this.genRandomNum();
		record.setBrandCode(code);
		return super.insert(record);
	}
	public String genRandomNum(){
		 int  maxNum = 36;  
	     int i;  
	     int count = 0;
	     char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K',  
	    	        'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',  
	    	        'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7', '8', '9' };
	     StringBuffer pwd = new StringBuffer("");
	     Random r = new Random();
	     while(count < 6){
	    	  i = Math.abs(r.nextInt(maxNum));
	    	  if (i >= 0 && i < str.length) {
	    		  pwd.append(str[i]); 
	    		  count ++; 
	    	  }
	     }
		return pwd.toString();
	}
}
